package com.eva.admin.api.system;

import com.eva.framework.common.api.BaseController;
import com.eva.admin.biz.system.SystemDepartmentBiz;
import com.eva.admin.biz.system.dto.UpdateSystemDepartmentDTO;
import com.eva.admin.biz.system.dto.CreateSystemDepartmentDTO;
import com.eva.admin.dao.system.vo.SystemDepartmentVO;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.rbac.authorize.ContainPermissions;
import com.eva.framework.security.prevent.PreventRepeat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "系统部门")
@RestController
@RequestMapping("/system/department")
public class SystemDepartmentController extends BaseController {

    @Resource
    private SystemDepartmentBiz systemDepartmentBiz;

    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @ContainPermissions("system:department:create")
    public ApiResponse<?> create(@RequestBody CreateSystemDepartmentDTO dto) {
        systemDepartmentBiz.create(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    @ContainPermissions("system:department:delete")
    public ApiResponse<?> deleteById(@PathVariable Integer id) {
        systemDepartmentBiz.deleteById(id);
        return ApiResponse.success(null);
    }

    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @ContainPermissions("system:department:delete")
    public ApiResponse<?> deleteByIdInBatch(@RequestParam String ids) {
        systemDepartmentBiz.deleteByIdInBatch(this.getIdList(ids));
        return ApiResponse.success(null);
    }

    @ApiOperation("修改")
    @PostMapping("/updateById")
    @ContainPermissions("system:department:update")
    public ApiResponse<?> updateById(@RequestBody UpdateSystemDepartmentDTO dto) {
        systemDepartmentBiz.updateById(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("查询所有")
    @PostMapping("/all")
    @ContainPermissions("system:department:query")
    public ApiResponse<List<SystemDepartmentVO>> findAll () {
        return ApiResponse.success(systemDepartmentBiz.findAll());
    }
}
